package com.ydh.company.exception;

import com.ydh.company.dto.ResponseData;
import com.ydh.company.dto.ResultData;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理类
 */

@RestControllerAdvice
public class MyExceptionHandler {

    /**
     * 捕获Exception及其子类的异常
     * @param e
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    ResultData exceptionHanlder(Exception e){
        return ResponseData.error(3001,"错误信息："+e.getMessage());
    }


    /**
     * 捕获文件上传相关的异常
     * @param e
     * @return
     */
    @ExceptionHandler(UploadException.class)
    ResultData uploadExceptionHanlder(UploadException e){
        return  ResponseData.error(e.getCode(),"文件上传异常："+e.getMsg());
    }

    /**
     * 捕获权限异常相关信息
     * @param e
     * @return
     */
    @ExceptionHandler(RbacException.class)
    ResultData rbacException(RbacException e){

        return ResponseData.error(e.getCode(),e.getMsg());
    }

}
